*********************************************
* Reassessing the Effects of Corporate Income Taxes on Mergers and Acquisitions Using			
* Empirical Advances in the Gravity Literature											
*		Bradley, Carril-Caccia and Yotov	
*										
* 		NTJ 2025								
*********************************************


**** Code for constructing the M&As database used for the empirical analysis



cd "C:\Data"

*************************************************
*************************************************
*************************************************
****** Country level database *******************
*************************************************
*************************************************
*************************************************

use MAraw.dta, clear


rename dealvalue mavolume
label var mavolume "M&A value in millions US"


keep if PercentageofSharesAcquiredin>50
gen project=1
label var nace2dg_scr "NACE Rev 2. 2 digit Acquirer"
label var nace2dg_dest "NACE Rev 2. 2 digit Target"

drop if nace2dg_scr==""
drop if nace2dg_dest==""

label var  ccode_scr "Ultimate acquirer country iso code"
label var ccode_dest "Target country iso code"

*** Restrict sample of countries
gen sample_dest=0
gen sample_scr=0

local mylisto  ALB	DZA	AGO	ARG	ARM	AUS	AUT	AZE	BHS	BHR	BGD	BRB	BLR	BEL	BLZ	BMU	BOL	BIH	BWA	BRA	BRN	BGR	BFA	KHM	CAN	CYM	TCD	CHL	CHN	COL	CRI	CIV	HRV	CYP	CZE	DNK	DOM	ECU	EGY	SLV	EST	ETH	FIN	FRA	GEO	DEU	GHA	GRC	GTM	HKG	HUN	ISL	IND	IDN	IRN	IRQ	IRL	ISR	ITA	JAM	JPN	JOR	KAZ	KEN	KOR	KWT	KGZ	LAO	LVA	LBN	LBY	LUX	MKD	MDG	MYS	MLT	MUS	MEX	MDA	MNG	MAR	MOZ	NAM	NLD	NCL	NZL	NIC	NGA	NOR	OMN	PAK	PAN	PNG	PRY	PER	PHL	POL	PRT	PRI	QAT	ROU ROM	RUS	RWA	WSM	SAU	SYC	SGP	SVK	SVN	ZAF	ESP	LKA	SWZ	SWE	CHE	TJK	TZA	THA	TTO	TUN	TUR	UGA	UKR	ARE	GBR	USA	URY	UZB	VEN	VNM	ZMB	ZWE
foreach o of local mylisto {
replace sample_dest=1 if ccode_dest=="`o'" 

}
local mylisto  ALB	DZA	AGO	ARG	ARM	AUS	AUT	AZE	BHS	BHR	BGD	BRB	BLR	BEL	BLZ	BMU	BOL	BIH	BWA	BRA	BRN	BGR	BFA	KHM	CAN	CYM	TCD	CHL	CHN	COL	CRI	CIV	HRV	CYP	CZE	DNK	DOM	ECU	EGY	SLV	EST	ETH	FIN	FRA	GEO	DEU	GHA	GRC	GTM	HKG	HUN	ISL	IND	IDN	IRN	IRQ	IRL	ISR	ITA	JAM	JPN	JOR	KAZ	KEN	KOR	KWT	KGZ	LAO	LVA	LBN	LBY	LUX	MKD	MDG	MYS	MLT	MUS	MEX	MDA	MNG	MAR	MOZ	NAM	NLD	NCL	NZL	NIC	NGA	NOR	OMN	PAK	PAN	PNG	PRY	PER	PHL	POL	PRT	PRI	QAT	ROU ROM	RUS	RWA	WSM	SAU	SYC	SGP	SVK	SVN	ZAF	ESP	LKA	SWZ	SWE	CHE	TJK	TZA	THA	TTO	TUN	TUR	UGA	UKR	ARE	GBR	USA	URY	UZB	VEN	VNM	ZMB	ZWE
foreach o of local mylisto {
replace sample_scr=1 if ccode_scr=="`o'" 

}

keep if sample_scr==1 & sample_dest==1


local mylisto 95 97
foreach o of local mylisto {
drop if nace2dg_scr=="`o'" 
drop if nace2dg_dest=="`o'" 

}

gen project=1

collapse (sum) project mavolume, by(ccode_scr ccode_dest  year)

fillin ccode_scr ccode_dest year
replace project=0 if project==.

local mylisto mavolume 
foreach o of local mylisto {
replace `o'=0 if  `o'==.
replace `o'=. if  `o'==0 & project!=0

}

egen dyad= group(ccode_scr ccode_dest)

sort dyad

by dyad: egen sum_zeros=sum(project)

drop if sum_zeros==0
drop sum_zeros

drop _fillin dyad 
compress
save country_temp.dta, replace

**** Code so a country appears in the database the first time it has a M&As transaction

local mylistd 1995	1996	1997	1998	1999	2000	2001	2002	2003	2004	2005	2006	2007	2008	2009	2010	2011	2012	2013	2014	2015	2016	2017	2018	2019 2020 2021 
foreach d of local mylistd {
use country_temp.dta, clear

keep if year==`d'
save tempcon_`d', replace
}


use tempcon_1995, clear
local mylistd	1996	1997	1998	1999	2000	2001	2002	2003	2004	2005	2006	2007	2008	2009	2010	2011	2012	2013	2014	2015	2016	2017	2018	2019 2020 2021
foreach d of local mylistd {

append using tempcon_`d'
** Source
egen scr=group(ccode_scr)
sort scr
by scr: egen zero=sum(project)
drop if zero==0
drop zero scr

* Target
egen dest=group(ccode_dest)
sort dest
by dest: egen zero=sum(project)
drop if zero==0
drop zero dest
}



save ma_country_data.dta, replace

****************************************
**** Add indepdent variables:***********
****************************************
**** Add CEPPI data
**** Distance, contiguity, language, colonial ties and RTA

cd "C:\Data\GravityVariables\"

merge m:1 ccode_scr ccode_dest year using Gravity_V202102.dta
drop if year<1995
drop if _merge==2
drop _merge


drop entry_cost_o entry_cost_d entry_proc_o entry_proc_d entry_time_o entry_time_d entry_tp_o entry_tp_d tradeflow_comtrade_o tradeflow_comtrade_d tradeflow_baci manuf_tradeflow_baci tradeflow_imf_o tradeflow_imf_d gdp_ppp_o gdp_ppp_d gdpcap_ppp_o gdpcap_ppp_d pop_pwt_o pop_pwt_d gdp_ppp_pwt_o gdp_ppp_pwt_d gdp_o gdp_d gdpcap_o gdpcap_d

gen lndistw=ln(distw)

**** Add bilateral investment treaties database (BIT)
cd "C:\Data\BilateralInvestmentTreaties"

merge m:1 ccode_scr ccode_dest using BIT2020new_full.dta
drop if _merge==2
drop _merge
/*
Variable      Storage   Display    Value
    name         type    format    label      Variable label
-----------------------------------------------------------------------------------------------------------------------------------
ccode_dest      str3    %9s                   ccode_dest
ccode_scr       str3    %9s                   ccode_dest
yrsig           float   %9.0g                 year of signature
yrforce         float   %9.0g                 year of entry force
yrterm          float   %9.0g                 year of temination
yrsig2          float   %9.0g                 year of signature
yrforce2        float   %9.0g                 year of entry force
yrterm2         float   %9.0g                 year of temination

*/




gen bitforce=0 if ccode_dest==ccode_scr
replace bitforce=0 if yrforce==. 

replace bitforce=1 if yrforce==year
replace bitforce=1 if yrforce<year & yrforce!=.
replace bitforce=0 if yrforce>year & yrforce!=.
replace bitforce=0 if yrterm==year
replace bitforce=0 if yrterm<year & yrterm!=.
replace bitforce=1 if yrforce2==year & bitforce==0
replace bitforce=1 if yrforce2<year & yrforce2!=. & bitforce==0
replace bitforce=0 if yrterm2==year
replace bitforce=0 if yrterm2<year & yrterm2!=.
replace bitforce=0 if ccode_dest==ccode_scr


drop yrsig yrforce yrterm yrsig2 yrforce2 yrterm2
label var bitforce "BIT dummy"


*** Add CIT data from Tax Foundation
cd "C:\Data\TaxFoundation"

merge m:1  ccode_dest year using corporatetax_taxfoundation.dta
drop if _merge==2
drop _merge

label var tax_rate "Corporate income tax (%), tax foundation"




***** Add exchange rates from IMF:
cd "C:\Data\ExchangeRate"

merge m:1 ccode_dest year using "nominalexchangeDEST19402019.dta"
keep if _merge==3
drop _merge 
gen lnexchange=ln(exchgr_dest)
label var lnexchange  "Exchange rate (log)"


**** Add data from World Bank's Development Indicators: 
*** Target country (destination) GDP, labor force, unemployment rate, inflation rate, and exports (%GDP)
cd "C:\Data\WDI"


merge m:1 ccode_dest year using wdi_destination.dta
keep if _merge==3
drop _merge

gen lngdp_d =ln(gdp_d)
label var lngdp_d "GDP (log)"

gen lnlabor_force_dest=ln(labor_force_dest)

label var unemploy_d "Unemployment rate"


label var inflation_dest "Inflation rate"

label var exports_dest "Exports (\%GDP)"




*** Source country: GDP and GDP per capita
merge m:1 ccode_scr year using wdi_source.dta
keep if _merge==3
drop _merge

gen lngdp_s=ln(gdp_s)
gen lngdppc_s=ln(gdppc_s)

label var lngdp_s "GDP scr (log)"
label var lngdppc_s "GDP pc scr  (log)"



**** Add Economic freedom
cd "C:\Data\EcoFreedom"
merge m:1 ccode_dest year  using eco_freedom_fraser.dta
drop if _merge==2
drop _merge

gen lneco_freedom_h=ln(eco_freedom_h)

label var lneco_freedom_h "Eco. Freedom (log)"



**** Add Diplomatic distance index
cd "C:\Data\UNvotes"
merge m:1 ccode_scr ccode_dest year using  "UNagreement.dta"
drop if _merge==2
drop if _merge==1 & ccode_scr!=ccode_dest
drop _merge
gen un_dist=real(idealpointdistance)
replace un_dist=0 if ccode_scr==ccode_dest

gen lnun_dist=ln(un_dist+1)

label var lnun_dist "Diplomatic distance"

cd "C:\Data\GSDB"

**** Add Sanctions

/* With the original sanction database:
use GSDB_V3_Dyadic.dta, clear
gen allsanctions=1
rename sanctioning_state_iso3  ccode_scr
rename sanctioned_state_iso3 ccode_dest
label var allsanctions "Any sanction"
save GSDB_V3_Dyadic.dta, replace

*/
merge m:1 ccode_scr ccode_dest year using "GSDB_V3_Dyadic.dta"

replace allsanctions=0 if allsanctions==.


** We incorporate the World Bank's income classification
merge m:1 ccode_dest year using "world bank income classification.dta"

drop if _merge==2

drop _merge

merge m:1 ccode_scr year using "world bank income classification_scr.dta"
drop if _merge==2

drop _merge

**** Add tax system classification:

merge m:1 ccode_scr year using taxsystems_scr.dta
drop if _merge==2
drop _merge

merge m:1 ccode_dest year using taxsystems_dest.dta
drop if _merge==2
drop _merge



compress
save ma_country_data.dta, replace



********************************************************
********************************************************
********************************************************
****** Country Sector level database *******************
********************************************************
********************************************************
********************************************************

cd "C:\Data"

use MAraw.dta, clear


rename dealvalue mavolume
label var mavolume "M&A value in millions US"


keep if PercentageofSharesAcquiredin>50
gen project=1
label var nace2dg_scr "NACE Rev 2. 2 digit Acquirer"
label var nace2dg_dest "NACE Rev 2. 2 digit Target"

drop if nace2dg_scr==""
drop if nace2dg_dest==""

label var  ccode_scr "Ultimate acquirer country iso code"
label var ccode_dest "Target country iso code"

*** Restrict sample of countries
gen sample_dest=0
gen sample_scr=0

local mylisto  ALB	DZA	AGO	ARG	ARM	AUS	AUT	AZE	BHS	BHR	BGD	BRB	BLR	BEL	BLZ	BMU	BOL	BIH	BWA	BRA	BRN	BGR	BFA	KHM	CAN	CYM	TCD	CHL	CHN	COL	CRI	CIV	HRV	CYP	CZE	DNK	DOM	ECU	EGY	SLV	EST	ETH	FIN	FRA	GEO	DEU	GHA	GRC	GTM	HKG	HUN	ISL	IND	IDN	IRN	IRQ	IRL	ISR	ITA	JAM	JPN	JOR	KAZ	KEN	KOR	KWT	KGZ	LAO	LVA	LBN	LBY	LUX	MKD	MDG	MYS	MLT	MUS	MEX	MDA	MNG	MAR	MOZ	NAM	NLD	NCL	NZL	NIC	NGA	NOR	OMN	PAK	PAN	PNG	PRY	PER	PHL	POL	PRT	PRI	QAT	ROU ROM	RUS	RWA	WSM	SAU	SYC	SGP	SVK	SVN	ZAF	ESP	LKA	SWZ	SWE	CHE	TJK	TZA	THA	TTO	TUN	TUR	UGA	UKR	ARE	GBR	USA	URY	UZB	VEN	VNM	ZMB	ZWE
foreach o of local mylisto {
replace sample_dest=1 if ccode_dest=="`o'" 

}
local mylisto  ALB	DZA	AGO	ARG	ARM	AUS	AUT	AZE	BHS	BHR	BGD	BRB	BLR	BEL	BLZ	BMU	BOL	BIH	BWA	BRA	BRN	BGR	BFA	KHM	CAN	CYM	TCD	CHL	CHN	COL	CRI	CIV	HRV	CYP	CZE	DNK	DOM	ECU	EGY	SLV	EST	ETH	FIN	FRA	GEO	DEU	GHA	GRC	GTM	HKG	HUN	ISL	IND	IDN	IRN	IRQ	IRL	ISR	ITA	JAM	JPN	JOR	KAZ	KEN	KOR	KWT	KGZ	LAO	LVA	LBN	LBY	LUX	MKD	MDG	MYS	MLT	MUS	MEX	MDA	MNG	MAR	MOZ	NAM	NLD	NCL	NZL	NIC	NGA	NOR	OMN	PAK	PAN	PNG	PRY	PER	PHL	POL	PRT	PRI	QAT	ROU ROM	RUS	RWA	WSM	SAU	SYC	SGP	SVK	SVN	ZAF	ESP	LKA	SWZ	SWE	CHE	TJK	TZA	THA	TTO	TUN	TUR	UGA	UKR	ARE	GBR	USA	URY	UZB	VEN	VNM	ZMB	ZWE
foreach o of local mylisto {
replace sample_scr=1 if ccode_scr=="`o'" 

}

keep if sample_scr==1 & sample_dest==1


local mylisto 95 97
foreach o of local mylisto {
drop if nace2dg_scr=="`o'" 
drop if nace2dg_dest=="`o'" 

}

gen project=1



collapse (sum) project mavolume, by(ccode_scr ccode_dest nace2dg_scr nace2dg_dest  year)

egen nace2dg_scr_code=group(nace2dg_scr)
egen nace2dg_dest_code=group(nace2dg_dest)
egen ccode_scr_code=group(ccode_scr)
egen ccode_dest_code=group(ccode_dest)

save tempa.dta, replace

drop  mavolume
save temp.dta, replace


preserve
duplicates drop nace2dg_scr_code, force
keep nace2dg_scr nace2dg_scr_code
save nace_source_code.dta, replace
restore

preserve
duplicates drop nace2dg_dest_code, force
keep nace2dg_dest nace2dg_dest_code
save nace_dest_code.dta, replace
restore

preserve
duplicates drop ccode_dest_code, force
keep ccode_dest ccode_dest_code
save dest_code.dta, replace
restore

preserve
duplicates drop ccode_scr_code, force
keep ccode_scr ccode_scr_code
save scr_code.dta, replace
restore

drop nace2dg_scr nace2dg_dest ccode_dest ccode_scr
compress
save temp.dta, replace

use temp.dta, clear
egen dupl=group(ccode_scr_code ccode_dest_code  nace2dg_scr_code nace2dg_dest_code)
sum dupl

duplicates drop dupl, force

keep ccode_scr_code ccode_dest_code  nace2dg_scr_code nace2dg_dest_code
save temp2.dta, replace


fillin ccode_scr_code ccode_dest_code  nace2dg_scr_code nace2dg_dest_code

save fillin_novo_comp.dta, replace


local mylistd  1995	1996	1997	1998	1999	2000	2001	2002	2003	2004	2005	2006	2007	2008	2009	2010	2011	2012	2013	2014	2015	2016	2017	2018	2019 2020 2021
foreach d of local mylistd {

use fillin_novo_comp.dta, clear

gen year= `d'
	
	merge 1:m ccode_scr_code ccode_dest_code nace2dg_scr_code nace2dg_dest_code year using temp.dta
tab _merge
drop _merge 
keep if year==`d'
replace project=0 if project==.
compress
	save fillin_novo_`d', replace

}

use fillin_novo_1995, clear
local mylistd	1996	1997	1998	1999	2000	2001	2002	2003	2004	2005	2006	2007	2008	2009	2010	2011	2012	2013	2014	2015	2016	2017	2018 2019
foreach d of local mylistd {

append using fillin_novo_`d'
** Source
egen scr=group(ccode_scr_code)
sort scr
by scr: egen zero=sum(project)
drop if zero==0
drop zero scr

* Target
egen dest=group(ccode_dest_code)
sort dest
by dest: egen zero=sum(project)
drop if zero==0
drop zero dest

** Source*Sector
egen scr=group(ccode_scr_code nace2dg_scr_code)
sort scr
by scr: egen zero=sum(project)
drop if zero==0
drop zero scr


* Target*Sector
egen dest=group(ccode_dest_code nace2dg_dest_code)
sort dest
by dest: egen zero=sum(project)
drop if zero==0
drop zero dest

}

save ma_sector_data.dta, replace





egen dyds= group(ccode_scr_code  ccode_dest_code)

sort dyds
by dyds: egen zero=sum(project)


drop if zero==0
drop zero
drop dyds


egen dyds= group(ccode_scr_code nace2dg_scr_code nace2dg_dest_code ccode_dest_code)

sort dyds
by dyds: egen zero=sum(project)

drop if zero==0
drop zero dyds
compress
save ma_sector_data.dta, replace

cd "G:\Mi unidad\Research\Projects\FDItax\Data"
use ma_sector_data.dta, clear
merge m:1 ccode_scr_code  using scr_code.dta
keep if _merge==3
drop _merge

merge m:1 ccode_dest_code  using dest_code.dta
keep if _merge==3
drop _merge

merge m:1 nace2dg_dest_code  using nace_dest_code.dta
keep if _merge==3
drop _merge


merge m:1 nace2dg_scr_code   using nace_source_code.dta
keep if _merge==3
drop _merge

merge 1:m ccode_scr_code ccode_dest_code nace2dg_scr_code nace2dg_dest_code year using tempa.dta
replace mavolume=0 if mavolume==.
replace mavolume2=0 if mavolume2==.
replace mavolume3=0 if mavolume3==.

replace mavolume=. if project!=0 & mavolume==0 
replace mavolume2=. if project!=0 & mavolume==0 
replace mavolume3=. if project!=0 & mavolume==0 
drop _merge

compress
save ma_sector_data.dta, replace


****************************************
**** Add indepdent variables:***********
****************************************

**** Add CEPPI data
**** Distance, contiguity, language, colonial ties and RTA

cd "C:\Data\GravityVariables\"

merge m:1 ccode_scr ccode_dest year using Gravity_V202102.dta
drop if year<1995
drop if _merge==2
drop _merge


drop entry_cost_o entry_cost_d entry_proc_o entry_proc_d entry_time_o entry_time_d entry_tp_o entry_tp_d tradeflow_comtrade_o tradeflow_comtrade_d tradeflow_baci manuf_tradeflow_baci tradeflow_imf_o tradeflow_imf_d gdp_ppp_o gdp_ppp_d gdpcap_ppp_o gdpcap_ppp_d pop_pwt_o pop_pwt_d gdp_ppp_pwt_o gdp_ppp_pwt_d gdp_o gdp_d gdpcap_o gdpcap_d

gen lndistw=ln(distw)

**** Add bilateral investment treaties database (BIT)
cd "C:\Data\BilateralInvestmentTreaties"

merge m:1 ccode_scr ccode_dest using BIT2020new_full.dta
drop if _merge==2
drop _merge
/*
Variable      Storage   Display    Value
    name         type    format    label      Variable label
-----------------------------------------------------------------------------------------------------------------------------------
ccode_dest      str3    %9s                   ccode_dest
ccode_scr       str3    %9s                   ccode_dest
yrsig           float   %9.0g                 year of signature
yrforce         float   %9.0g                 year of entry force
yrterm          float   %9.0g                 year of temination
yrsig2          float   %9.0g                 year of signature
yrforce2        float   %9.0g                 year of entry force
yrterm2         float   %9.0g                 year of temination

*/




gen bitforce=0 if ccode_dest==ccode_scr
replace bitforce=0 if yrforce==. 

replace bitforce=1 if yrforce==year
replace bitforce=1 if yrforce<year & yrforce!=.
replace bitforce=0 if yrforce>year & yrforce!=.
replace bitforce=0 if yrterm==year
replace bitforce=0 if yrterm<year & yrterm!=.
replace bitforce=1 if yrforce2==year & bitforce==0
replace bitforce=1 if yrforce2<year & yrforce2!=. & bitforce==0
replace bitforce=0 if yrterm2==year
replace bitforce=0 if yrterm2<year & yrterm2!=.
replace bitforce=0 if ccode_dest==ccode_scr


drop yrsig yrforce yrterm yrsig2 yrforce2 yrterm2
label var bitforce "BIT dummy"


*** Add CIT data from Tax Foundation
cd "C:\Data\TaxFoundation"

merge m:1  ccode_dest year using corporatetax_taxfoundation.dta
drop if _merge==2
drop _merge

label var tax_rate "Corporate income tax (%), tax foundation"




***** Add exchange rates from IMF:
cd "C:\Data\ExchangeRate"

merge m:1 ccode_dest year using "nominalexchangeDEST19402019.dta"
keep if _merge==3
drop _merge 
gen lnexchange=ln(exchgr_dest)
label var lnexchange  "Exchange rate (log)"


**** Add data from World Bank's Development Indicators: 
*** Target country (destination) GDP, labor force, unemployment rate, inflation rate, and exports (%GDP)
cd "C:\Data\WDI"


merge m:1 ccode_dest year using wdi_destination.dta
keep if _merge==3
drop _merge

gen lngdp_d =ln(gdp_d)
label var lngdp_d "GDP (log)"

gen lnlabor_force_dest=ln(labor_force_dest)

label var unemploy_d "Unemployment rate"


label var inflation_dest "Inflation rate"

label var exports_dest "Exports (\%GDP)"




*** Source country: GDP and GDP per capita
merge m:1 ccode_scr year using wdi_source.dta
keep if _merge==3
drop _merge

gen lngdp_s=ln(gdp_s)
gen lngdppc_s=ln(gdppc_s)

label var lngdp_s "GDP scr (log)"
label var lngdppc_s "GDP pc scr  (log)"



**** Add Economic freedom
cd "C:\Data\EcoFreedom"
merge m:1 ccode_dest year  using eco_freedom_fraser.dta
drop if _merge==2
drop _merge

gen lneco_freedom_h=ln(eco_freedom_h)

label var lneco_freedom_h "Eco. Freedom (log)"



**** Add Diplomatic distance index
cd "C:\Data\UNvotes"
merge m:1 ccode_scr ccode_dest year using  "UNagreement.dta"
drop if _merge==2
drop if _merge==1 & ccode_scr!=ccode_dest
drop _merge
gen un_dist=real(idealpointdistance)
replace un_dist=0 if ccode_scr==ccode_dest

gen lnun_dist=ln(un_dist+1)

label var lnun_dist "Diplomatic distance"

cd "C:\Data\GSDB"

**** Add Sanctions

/* With the original sanction database:
use GSDB_V3_Dyadic.dta, clear
gen allsanctions=1
rename sanctioning_state_iso3  ccode_scr
rename sanctioned_state_iso3 ccode_dest
label var allsanctions "Any sanction"
save GSDB_V3_Dyadic.dta, replace

*/
merge m:1 ccode_scr ccode_dest year using "GSDB_V3_Dyadic.dta"

replace allsanctions=0 if allsanctions==.







compress
save ma_sector_data.dta, replace





